package com.hrm.controller.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.hrm.model.dto.login.LoginDTO;
import com.hrm.model.service.LoginService;

public class LoginController extends AbstractFormController{
	
	private LoginService loginService;
	
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ModelAndView mv = new ModelAndView();
		
		LoginDTO dto = loginService.getLogin((LoginDTO)command);
		request.getSession().setAttribute("login", dto);
		
		mv.setViewName("main");
		return mv;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException errors) throws Exception {
		return new ModelAndView("login");
	}
}
